<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>${_front_title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/static/favicon.ico"/>
    <link rel="stylesheet" href="/static/front/fonts/iconfont.css">
    <link rel="stylesheet" href="/static/front/css/base_new.css">
    <link rel="stylesheet" href="/static/front/css/library.css">
    <link rel="stylesheet" href="/static/front/css/style.css">
    <script src="/static/front/js/jquery-1.11.1.min.js"></script>
    <script src="/static/front/js/jquery.countdown.js"></script>
    <script src="/static/front/js/js.js"></script>
    <!--[if lt IE 9]>
    <script src="/static/front/js/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script type="text/javascript" src="plugIn/PIE.js"></script>
    <![endif]-->
    <style>
      button{
		    margin-top: -40px;
		    cursor: pointer;
		    width: 78px;
		    height: 25px;
		    border: #4db0c2 1px solid;
		    background: #5dc0d2;
		    color: #fff;
		    border-radius: 3px;
		    -webkit-border-radius: 3px;
		    -moz-border-radius: 3px;
		    -ms-border-radius: 3px;
		    text-align: center;
		    line-height: 25px;      
		    margin-left: 80px;
      }
      td{
      	    padding-top: 20px;
      }
      td .tb-l{
	    width: 110px;
	    display: inline-block;
      }
    </style>
</head>

<body>
    <!-- 头部 开始 -->
    <div id="header">
		<#include "../base/top.ftl" />
	</div>
	<!-- 头部 结束 -->
    <div class="content">
    <div id="myInvestmentMain" class="cnt clearfix layoutMain">
       <#include "base1.ftl" />
     
        <div class="investment fr">
            <h2>自动投标</h2>
            <div class="Tab" style="margin-top: 48px;">
                <span data="auto_explain" class="TabOne tableTab active" style="display:inline-block;">关于自动投标</span>
                <span data="auto_set" class="TabTwo tableTab" style="display:inline-block;">自动投标设置</span>
                <span data="auto_record" class="TabThree tableTab" style="display:inline-block;">自动投标记录</span>
                <!-- 自动投标说明开始 -->
                 <table id="auto_explain" class="tabLibrary receivables" border="0" cellspacing="0" cellpadding="0" style='margin-top: 0px;display:block;'>
                 	<tbody style='display:block;padding-top:0px'>
	                 	<tr style='display:block;height:40px;padding-left: 15px;border-top:1px solid #ccc;border-left:1px solid #ccc;border-right:1px solid #ccc;'>
	                 		<td style="display: block;width:100%;text-align:left;border:none;">自动投标是一种快捷投标方式。自己选规则，列表满足条件，系统帮你投标。</td>
	                 	</tr>
	                 	<tr style='display:block;height:40px;padding-left: 15px;border-left:1px solid #ccc;border-right:1px solid #ccc;'>
	                 		<td style="display: block;width:100%;text-align:left;border:none;">1.筛选投资规则</td>
	                 	</tr>
	                 	<tr style='display:block;height:40px;padding-left: 15px;border-left:1px solid #ccc;border-right:1px solid #ccc;'>
	                 		<td style="display: block;width:100%;text-align:left;border:none;">2.设置投标条件</td>
	                 	</tr>
	                 	<tr style='display:block;height:40px;padding-left: 15px;border-left:1px solid #ccc;border-right:1px solid #ccc;'>
	                 		<td style="display: block;width:100%;text-align:left;border:none;">3.确定开启该规则</td>
	                 	</tr>
	                 	<tr style='display:block;height:40px;padding-left: 15px;border-left:1px solid #ccc;border-right:1px solid #ccc;border-bottom: 1px solid #ccc;'>
	                 		<td style="display: block;width:100%;text-align:left;border:none;">系统会按照您设置的规则，15分钟自动帮您投标。</td>
	                 	</tr>
             		</tbody>
             	</table>
                <!-- 自动投标说明结束 -->
                <!-- 自动投标设置开始 -->
                <table id="auto_set" class="tabLibrary receivables" border="0" cellspacing="0" cellpadding="0" style='margin-top: 0px;display:none;'>
                 	<tbody style='display:block;padding-top:0px'>
	                 	<tr style='display:block; border-top:1px solid #ccc;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display:block;text-align:left;width:100%;height:30px;border:none">
			                 	<p class="tb-l">账户可用余额：</p>
			                 	<span>
				                 	<#if account?? & account.balance??>
				            			<#if (account.balance != 0 )>
				                    		${account.balance?string(',##0.00')}元
				                    	<#else>
				                    	 	0.00元
				                    	</#if>
				                	<#else>
				                		0.00元
				                	</#if>
			                	</span>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:30px;border:none">
		                 		<p class="tb-l">单次投标金额：</p>
		                 		<input type="text" class="test" name="amount" id="amount" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' value="${(auto.money)!""}"
	                            onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
	                            ><span>元</span>
	                            <input type="hidden" id="itemId" value="${(auto.id)!""}"/>
	                    		<input type="hidden" id="status" value="${(auto.status)!""}"/>
	                            <span style="color:#ff7f50; float: none;display: inline;margin-left: 10px;">(需为1或不小于50且不大于自动投标总额的倍数)</span>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:30px;border:none">
			                 	<p class="tb-l">年利率范围：</p>
		                        <input type="text" class="test Wdate" name="min-percent" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' value="${(auto.minPercent)!""}" id="min-percent"
		                        onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
		                        >
		                        <span>%</span>
		                        <span style="color:#bbb">——</span>
		                        <input type="text" class="test Wdate" name="max-percent" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' value="${(auto.maxPercent)!""}" id="max-percent"
		                        onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
		                        >
		                        <span>%</span>
		                        <span style="color:#ff7f50; float: none;display: inline;margin-left: 10px;">(建议设置为5~24)</span>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:30px;border:none">
			                 	<p class="tb-l">借款期限范围：</p>
			                    <input type="text" class="test Wdate" name="min-month" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' value="${(auto.minPeriod)!""}" id="min-month"
			                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
			                    >
			                    <span>月</span>
			                    <span style="color:#bbb">——</span>
			                    <input type="text" class="test Wdate" name="max-month" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' value="${(auto.maxPeriod)!""}" id="max-month"
			                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
			                    >
			                    <span>月</span>
			                    <span style="color:#ff7f50; float: none;display: inline;margin-left: 10px;">(有效值是1~36)</span>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:30px;border:none">
		                 		<p class="tb-l">借款还款方式：</p>
	                            <select name="payMothod" id="payMothod" style="height: 30px;width:170px">
	                            	<option value="-1" <#if (!auto?? || auto.paymentMode==-1)>selected="selected"</#if>>不限</option>
	                                <option value="1" <#if (auto?? & auto.paymentMode==1)>selected="selected"</#if>>一次性还款</option>
	                                <option value="4" <#if (auto?? & auto.paymentMode==4)>selected="selected"</#if>>按月付息到期还本</option>
	                                <option value="3" <#if (auto?? & auto.paymentMode==3)>selected="selected"</#if>>等额本息</option>
	                            </select>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:30px;border:none">
			                 	<p class="tb-l">保留可用余额：</p>
			                    <input type="text" class="test" style='height: 30px;border:1px solid #d2dadf;margin-right:10px;' name="remandAmount" id="remandAmount"
			                    maxlength="9" value="${(auto.reserveFund)!""}" 
			                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
			                    ><span>元</span>
			                    <span style="color:#ff7f50; float: none;display: inline;margin-left: 10px;">(保留可用余额=账户可用余额-单次投标金额)</span>
		                 	</td>
	                 	</tr>
	                 	<tr style='display:block;border-left:1px solid #ccc;border-right:1px solid #ccc;border-bottom:1px solid #ccc;padding-left: 15px;'>
		                 	<td style="display: block;text-align:left;width:100%;height:80px;border:none;">
			                 	<#if auto??>
		                    		<#if auto.status==0>
		                    			<button class="but button1" id="save" style="margin-top:20px;">修改</button>
		                    			<button class="but button2" id="open" style="margin-top:20px;" onclick="change()" >开启</button>
		                    			<button class="but button3" onclick="javascript:;" id="close" style="margin-top:20px;">关闭</button>
		                    		<#else>
		                    			<button class="but button1 button3" id="save" style="margin-top:20px;">修改</button>
		                    			<button class="but button3" onclick="javascript:;" id="open" style="margin-top:20px;">开启</button>
		                    			<button class="but button2" id="close" onclick="change()" style="margin-top:20px;">关闭</button>
		                    		</#if>
		                    	<#else>
		                    	 	<button class="but button1" id="save" style="margin-top:20px;">保存</button>
		                    		<button class="but button3" onclick="javascript:;" id="open" style="margin-top:20px;">开启</button>
		                    		<button class="but button3" onclick="javascript:;" id="close" style="margin-top:20px;">关闭</button>
		                    	</#if>
		                 	</td>
	                 	</tr>
             		</tbody>
             	</table>
                <!-- 自动投标设置结束 -->
                <!--自动投标记录开始-->
                <table id="auto_record" class="tabLibrary receivables" border="0" cellspacing="0" cellpadding="0" style='margin-top: 0px;display:none;'>
                    <tbody style='display:block;'>
	                    <tr>
	                        <th class="one" style="text-align:center;float:left;line-height:40px;width:196px;">借款标题</th>
	                        <th class="two" style="text-align:center;float:left;line-height:40px;width:140px;">借款类型</th>
	                        <th class="three" style="text-align:center;float:left;line-height:40px;width:140px;">年利率（%）</th>
	                        <th class="four" style="text-align:center;float:left;line-height:40px;width:140px;">期限</th>
	                        <th class="five" style="text-align:center;float:left;line-height:40px;width:140px;">借出金额（元）</th>
	                        <th class="six" style="text-align:center;float:left;line-height:40px;width:140px;">进度</th>
	                        <th class="seven" style="text-align:center;float:left;line-height:40px;width:81px;">状态</th>
	                    </tr>
                   			<#if ((pageInfo?exists) & (pageInfo.pageList?size>0))>
                        		<#list pageInfo.pageList as model>
				                    <tr>
				                        <td class="one" style="text-align:-webkit-center">
				                        	<#if model.title?exists>${model.title}</#if>
				                        </td>
				                        <td class="two">
				                           	 <#if model.productId?exists && model.productId==3>
				                           	 	车贷E通
				                           	 <#elseif (model.productId?exists && model.productId==4)>
				                           	 	车商贷
				                           	 <#elseif model.productId?exists && model.productId==5>
				                           	 	房E贷
				                           	 <#elseif model.productId?exists && model.productId==6>
				                           	 	商易贷
				                           	 <#elseif model.productId?exists && model.productId==7>
				                           	 	抵押贷
				                           	 </#if>
				                        </td>
				                        <td class="three">
											<#if model.percent?exists>${model.percent}</#if>
				                        </td>
				                        <td class="four">
				                        	<#if (model.dateUtil?exists) && (model.dateUtil == "MONTH")>
	                      						<#if model.deadline?exists>${model.deadline}个月</#if>
	                      					<#elseif (model.dateUtil?exists) && (model.dateUtil == "DAY")>
	                      						<#if model.deadline?exists>${model.deadline}天</#if>
	                      					</#if>
				                        </td>
				                        <td class="five">
				                        	<#if model.tenderMoney?exists>${model.tenderMoney?string(",###.00")}</#if>
				                        </td>
				                        <td class="six">
				                        	<#if model.schedules?exists>${model.schedules}</#if>
				                        </td>
				                        <td class="seven">
				                        	<#if model.status?exists && model.status=='borrow'>
				                        		投标中
			                        		<#elseif model.status?exists && model.status=='pay'>
			                        			还款中
			                        		<#elseif model.status?exists && model.status=='complete'>
			                        			已完成
				                        	</#if>
				                        </td>
				                    </tr>
			                    </#list>
			                <#else>
			                	<tr style='display:block;'><td style="display: block;width:100%;height:30px;">暂无数据</td></tr>
		                    </#if>
                	</tbody>
                </table>
                <!--自动投标记录结束-->
            </div>
            <!-- 分页组件 -->
           <#if (pageInfo??) & (pageInfo.pageList?size>0)>
            	<div id="auto_record1" class="tcdPageCode" style='display:none;'></div>
            </#if>
        </div>
    </div>
    <div id="footer">
      <div class="content">      
		<#include "../base/foot.ftl" />
      </div>
    </div>       
</div>
	<script type="text/javascript" src="${_front_js}/jquery.page.js"></script>
    <script type="text/javascript" src="${_front_js}/tabs.js"></script>
    <script type="text/javascript" src="${_front_js}/layer/layer.js" ></script>
<script>
	$(".tcdPageCode").createPage({
	    pageCount:${pageInfo.pages},//总页数
	    current:${pageInfo.index},
	    backFn:function(index){
	        window.location.href="/account/auto?index="+index;
	    }
	});
 	$(".TabOne").click(function(){
 		var temp = $(this).attr("data");
 		
 		$(".active").removeClass("active");
 		$(this).addClass("active");
 		$('.investment .tabLibrary').hide();
 		document.getElementById('auto_explain').style.display='block';
 		document.getElementById('auto_record1').style.display='none';
 	})
 	$(".TabTwo").click(function(){
 		var temp = $(this).attr("data");
 		$(".active").removeClass("active");
 		$(this).addClass("active");
 		$('.investment .tabLibrary').hide();
 		document.getElementById('auto_set').style.display='block';
 		document.getElementById('auto_record1').style.display='none';
 	})
 	$(".TabThree").click(function(){
 		var temp = $(this).attr("data");
 		$(".active").removeClass("active");
 		$(this).addClass("active");
 		$('.investment .tabLibrary').hide();
 		document.getElementById('auto_record').style.display='block';
 		document.getElementById('auto_record1').style.display='block';
 	})	

	$('input').blur(function(){
	  var value=$(this).val();
	  if(value!=""){
    	  $(this).val(parseInt(value));
	  }    		
	})
    	
	$("#save").click(function(){
		var balance=${account.balance};
		var id=$("#itemId").val();
		var status=$("#status").val();
		var amount=$.trim($("#amount").val());
		var min_percent=$.trim($("#min-percent").val());
		var max_percent=$.trim($("#max-percent").val());
		var min_month=$.trim($("#min-month").val());
		var max_month=$.trim($("#max-month").val());
		var payMothod=$.trim($("#payMothod").val());
		var remandAmount=$.trim($("#remandAmount").val());
		if(amount==""){
			layer.alert("请设置单次投标金额");
			return false;
		}
		if(!isNumberBy100(amount)){
			layer.alert("单次投标金额需为100的整数倍");
			return false;
		}
		if(min_percent==""){
			layer.alert("请设置最小年化率");
			return false;    			
		}
		if(max_percent==""){
			layer.alert("请设置最大年化率");
			return false;    			
		} 
		if(parseInt(min_percent)>parseInt(max_percent)){
			layer.alert("年化率设置有误");
			return false;
		} 
		if(min_month==""){
			layer.alert("请设置最小期限");
			return false;    			
		}
		if(max_month==""){
			layer.alert("请设置最大期限");
			return false;    			
		} 
		if(parseInt(min_month)>parseInt(max_month)){
			layer.alert("借款期限设置有误");
			return false;
		}  
		if(remandAmount==""){
			layer.alert("请设置保留可用余额");
			return false;
		}else if(parseInt(remandAmount)>balance-parseInt(amount)){
			layer.alert("保留可用余额金额有误，请参考右侧公式!");
			return false;
		}
		var tenderAuto={
			minPercent:min_percent,
			maxPercent:max_percent,
			minPeriod:min_month,
			maxPeriod:max_month,
			paymentMode:payMothod,
			reserveFund:remandAmount,
			money:amount,
			id:id,
			status:status
		};
		$.ajax({
            type: "POST",
            url:"/front/auto/save",
            data:JSON.stringify(tenderAuto),
            async: false,
            dataType:'JSON',
            contentType:'application/json;charset=UTF-8', 
            success: function(result){
            	if(result.code == -1){
            		layer.alert("设置成功!", function(index){
					    layer.close(index);
					    window.location.reload();
					});  
            	}else{
            		layer.alert(result.msg);
            	}
            }
        });        		
	})

	function change(){
		layer.confirm('您确定开通第三方自动投标托管？', function(index){
			window.location.href = "/hf/account/tender/auto";
			layer.close(index);
		});  
	}
 		
	function isNumberBy100(num) {
		var re = /^[0-9]*[0-9]$/i;
		if((re.test(num) && num%100===0)) {
			return true;
		}else {
			return false;
		}
	}
</script>
</body>
</html>
